﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.Core;
using Castle.Windsor;
using Castle.Windsor.Configuration;
//using Castle.MicroKernel.SubSystems.Configuration;
using Castle.MicroKernel.Registration;
using Tracker.Data.EFDAL;
using Tracker.Services;
using System.Configuration;

namespace Tracker.Helper
{
    /// <summary>
    /// Castle Windsor IOC configuration and wrapper
    /// </summary>
   public  class CastleWindsor
    {
            private static IWindsorContainer _container = new WindsorContainer();

            public static IWindsorContainer Container
            {
                get { return _container; }
            }

            public static void Configure()
            {
                Container.Register(
                    Component.For<DataEntities>()
                        .ImplementedBy<DataEntities>()
                        .DependsOn(Parameter.ForKey("connectionString")
                        .Eq(ConfigurationManager
                            .ConnectionStrings["tracker"].ConnectionString)),
                    Component.For<ITaskData>()
                        .ImplementedBy<TaskData>(),
                    Component.For<Helper.CastleWindsor>()
                        .ImplementedBy<Helper.CastleWindsor>(),
                    Component.For<Helper.AppSetting>()
                        .ImplementedBy<Helper.AppSetting>()
                    );
            }
            public static T Resolve<T>()
            {
                return _container.Resolve<T>();
            }

            public static void Register<T>() where T : class
            {
                Container.Register(
                    Component.For<T>()
                    .ImplementedBy<T>().LifestyleTransient()
                );
            }

            public static void Register<I, T>()
                where T : class,I
                where I : class
            {
                Container.Register(
                    Component.For<I>()
                    .ImplementedBy<T>().LifestyleTransient()
                );
            }
       
    }
}
